package com.liyunc.demo.model.repository;

import com.liyunc.demo.model.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface RoleRepository extends JpaRepository<Role, Long> {

    Role findRoleByName(String name);

    @Query(value = "SELECT * "
        + " FROM role "
        + " LEFT JOIN `user_roles` on role.id=`user_roles`.roles_id "
        + " LEFT JOIN `user` ON `user`.id=`user_roles`.user_id"
        + " WHERE username = ?1", nativeQuery = true)
    List<Role> getRolesByUserName(String username);
}
